package com.netty.bfport.http.common;

import com.netty.bfport.http.common.base.BaseResponse;
import com.netty.bfport.http.common.base.BaseResponseVO;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: zhaoyang05
 * @Data: 2022/3/23 15:55
 * @Description
 */
@RestControllerAdvice
public class AllExceptionController {

    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    public BaseResponseVO AllException(MethodArgumentNotValidException ex){
        FieldError fieldError = ex.getBindingResult().getFieldError();
        if (fieldError!=null) {
            return BaseResponse.setResultError(fieldError.getDefaultMessage());
        }
        return BaseResponse.setResultError("异常");
    }
}
